import numpy as np
import os

'''
print('1 > ')
input_all = []
eachinput = input()
while eachinput.isspace()==False:
  input_all.append(eachinput)
  eachinput = input()
var1 = '\n'.join(input_all)

print('2 > ')
input_all = []
eachinput = input()
while eachinput.isspace()==False:
  input_all.append(eachinput)
  eachinput = input()
var2 = '\n'.join(input_all)
'''
var1_f = '1.1.txt'
var2_f = '1.2.txt'

os.chdir(os.path.dirname(os.path.abspath(__file__)))
var1 = open(var1_f,encoding='utf8').read()
var2 = open(var2_f,encoding='utf8').read()

#print(len(var1), '>', var1)
#print(len(var2), '>', var2)

var1_1 = np.asarray(list(map(ord,var1)), dtype=int)
var2_1 = np.asarray(list(map(ord,var2)), dtype=int)

var1_2 = np.nditer(var1_1, flags=['f_index'])
#var2_2 = np.nditer(var2_1, flags=['f_index'])

var4 = np.asarray([], dtype=np.int16)
while not var1_2.finished:
  var3 = var1_1[var1_2.index]
  try:
    var3_1 = var1_1[var1_2.index+1]
    var2_3 = np.nditer(np.where(var2_1==var3)[0])
    while not var2_3.finished:
      try:
        if var3_1 == var2_1[var2_3[0]+1]:
          var4 = np.append(var4, (var1_2.index, var1_2.index+1))
      except: pass
      var2_3.iternext()
    var2_3.reset()
  except: pass
  var1_2.iternext()

var5 = var1_1[np.sort(np.unique(var4))]
#print(''.join(list(map(chr, var5.tolist()))))
print("%i of %i ( %.3f%% ) Similiar-with %i ( %.3f%% )" %(len(var5),len(var1_1),(len(var5)/len(var1_1)*100),len(var2_1),(len(var5)/len(var2_1)*100)))
